//
//  DetailController.m
//  ApoioLivre
//
//  Created by Tarek Abdala on 11/11/10.
//  Copyright 2010 UFSC - Universidade Federal Santa Catarina. All rights reserved.

#import "MovimentoController.h"
#import "LancamentoController.h"
#import "Lancamento.h"
#import "JSON.h"

@implementation MovimentoController

@synthesize txtValor, txtDescricao, txtCategoria;
@synthesize lancamentoController;


- (IBAction)textFieldShouldReturn {
}

-(IBAction)showLancamento:(id)sender{
	
	lancamentoController = [[LancamentoController alloc] initWithNibName:@"LancamentoController" bundle:nil];
	
	//[self presentModalViewController:lancamentoController animated:YES];
	
	
	[self.navigationController pushViewController:lancamentoController
										 animated:YES];
	
	UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Registra Movimentação" style: UIBarButtonItemStyleBordered target: nil action: nil];
	[[self navigationItem] setBackBarButtonItem: newBackButton];
	
	[lancamentoController release];
	[newBackButton release];
}


-(IBAction)registraMovimentacao:(id)sender{
	
	//Confirma Movimentação
    UIAlertView *alert = [[UIAlertView alloc] init];
	[alert setTitle:@"Cadastro Novo Movimento"];
	[alert setMessage:@"Deseja Realmente Cadastrar Novo Movimento?"];
	[alert setDelegate:self];
	[alert addButtonWithTitle:@"Cancela"];
	[alert addButtonWithTitle:@"Registrar"];
	[alert show];
	
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	//Cancela Registro.
	if (buttonIndex == 0){
		NSLog(@"Index0");
	}
	else if (buttonIndex == 1){
		
		//Bean Lancamento Movimento
		Lancamento *lancamento	= [[Lancamento alloc] init];
		lancamento.valor		= [NSNumber numberWithInt:[txtValor.text intValue]];
		lancamento.descricao	= txtDescricao.text;
		lancamento.categoria	= txtCategoria.text;

		//[LancamentoController.tableView insertRowsAtIndexPaths:<#(NSArray *)indexPaths#> withRowAnimation:<#(UITableViewRowAnimation)animation#>];
	}
}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
 // Custom initialization
 }
 return self;
 }
 */


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */
/*
 - (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
 [super didReceiveMemoryWarning];
 
 // Release any cached data, images, etc that aren't in use.
 }
 */
/*
 - (void)viewDidUnload {
 [super viewDidUnload];
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
 }
 */

- (void)dealloc {
	[txtValor release];
    [super dealloc];
}


@end